package com.huawei.appmarket.service.store.awk.card;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appmarket.service.store.awk.bean.BaseMultipleLineVerticalCardBean;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.cgz;
import o.chy;
import o.dof;
import o.eib;
import o.CollectCheck;
import o.evx;
import o.ewm.d;
import o.ewm.j;

public class BaseMultipleLineVerticalCard extends cgz {
    protected List<LinearLayout> ʻ = new ArrayList();
    protected View ʼ;
    protected int ʽ = 0;
    protected chy ˊ;
    protected View ˋ;
    protected View ˎ;
    protected int ˏ = 6;
    private List<BaseDistCard> ˏॱ = new ArrayList();
    protected View ॱ;
    protected int ॱॱ;
    protected LinearLayout ᐝ;

    public BaseMultipleLineVerticalCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        ॱ((TextView) view.findViewById(j.ʼﾞ));
        this.ʼ = view.findViewById(j.ʾᐝ);
        this.ॱ = view.findViewById(j.ˈʾ);
        this.ˎ = view.findViewById(j.ʼꞌ);
        this.ᐝ = (LinearLayout) view.findViewById(j.יˊ);
        this.ˋ = view.findViewById(j.ᐣ);
        azb.ˏ(this.ॱ);
        ˋ(this.ᐝ);
        ॱ(this.ˋ);
        ʽ(view);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof BaseMultipleLineVerticalCardBean) {
            BaseMultipleLineVerticalCardBean baseMultipleLineVerticalCardBean = (BaseMultipleLineVerticalCardBean) cardBean;
            if (ॱ(baseMultipleLineVerticalCardBean)) {
                this.ʼ.setVisibility(0);
                ˏ(baseMultipleLineVerticalCardBean);
                this.ॱॱ = ॱॱ();
                int min = Math.min(baseMultipleLineVerticalCardBean.ˊ().size(), this.ˏ);
                ˎ(min);
                ˋ(min);
                ˋ(baseMultipleLineVerticalCardBean, min);
                this.ʽ = this.ॱॱ;
                return;
            }
            this.ʼ.setVisibility(8);
        }
    }

    private void ˎ(int i) {
        if (ᐝ()) {
            this.ᐝ.removeAllViews();
            for (LinearLayout removeAllViews : this.ʻ) {
                LinearLayout removeAllViews2;
                removeAllViews2.removeAllViews();
            }
        }
        if (this.ॱॱ != 1) {
            int size = this.ʻ.size() * this.ॱॱ;
            int childCount = this.ᐝ.getChildCount();
            int i2 = childCount;
            while (childCount < this.ʻ.size()) {
                this.ᐝ.addView((View) this.ʻ.get(i2));
                i2++;
            }
            i2 = size;
            while (i2 - this.ॱॱ >= i) {
                removeAllViews2 = (LinearLayout) this.ʻ.get(this.ʻ.size() - 1);
                this.ᐝ.removeView(removeAllViews2);
                this.ʻ.remove(removeAllViews2);
                i2 -= this.ॱॱ;
            }
            while (i2 < i) {
                View ʻ = ʻ();
                this.ʻ.add(ʻ);
                this.ᐝ.addView(ʻ);
                i2 += this.ॱॱ;
            }
        } else if (!CollectCheck.isEmpty(this.ʻ)) {
            this.ʻ.clear();
        }
    }

    protected void ˋ(int i) {
        if (this.ॱॱ == 1) {
            ॱ(i);
        } else {
            ʼ();
        }
    }

    private void ॱ(int i) {
        int childCount;
        for (childCount = this.ᐝ.getChildCount(); childCount < this.ˏॱ.size(); childCount++) {
            this.ᐝ.addView(((BaseDistCard) this.ˏॱ.get(childCount)).ˉ());
        }
        int size = this.ˏॱ.size();
        for (childCount = size; i < childCount; childCount--) {
            this.ˏॱ.remove(childCount - 1);
            this.ᐝ.removeViewAt(childCount - 1);
        }
        while (i - size > 0) {
            ॱ(this.ᐝ);
            size++;
        }
    }

    private void ʼ() {
        int i = 0;
        int size = this.ʻ.size();
        for (int size2 = this.ˏॱ.size(); size2 - (this.ॱॱ * size) > 0; size2--) {
            this.ˏॱ.remove(this.ˏॱ.get(size2 - 1));
        }
        int size3 = this.ˏॱ.size();
        for (int i2 = 0; i2 < this.ʻ.size(); i2++) {
            LinearLayout linearLayout = (LinearLayout) this.ʻ.get(i2);
            int childCount = linearLayout.getChildCount();
            for (int i3 = 1; i3 <= this.ॱॱ; i3++) {
                int i4 = ((this.ॱॱ * i2) + i3) - 1;
                if (i3 > childCount && i4 < size3) {
                    linearLayout.addView(((BaseDistCard) this.ˏॱ.get(i4)).ˉ());
                }
            }
        }
        while (i < size) {
            ViewGroup viewGroup = (LinearLayout) this.ʻ.get(i);
            for (i4 = viewGroup.getChildCount(); i4 < this.ॱॱ; i4++) {
                ॱ(viewGroup);
            }
            i++;
        }
    }

    private void ˋ(BaseMultipleLineVerticalCardBean baseMultipleLineVerticalCardBean, int i) {
        int size = this.ˏॱ.size();
        List ˊ = baseMultipleLineVerticalCardBean.ˊ();
        ˎ(i, ˊ);
        int i2 = 0;
        while (i2 < size) {
            BaseDistCard baseDistCard = (BaseDistCard) this.ˏॱ.get(i2);
            if (i > i2) {
                BaseDistCardBean baseDistCardBean = (BaseDistCardBean) ˊ.get(i2);
                baseDistCardBean.ˋˋ(baseMultipleLineVerticalCardBean.ॱˉ());
                baseDistCard.ˏ(baseDistCardBean);
                baseDistCard.ˉ().setVisibility(0);
            } else {
                baseDistCard.ˉ().setVisibility(4);
            }
            if (this.ॱॱ != 0) {
                LayoutParams layoutParams = (LayoutParams) baseDistCard.ˉ().getLayoutParams();
                if (this.ॱॱ == 1) {
                    layoutParams.width = -1;
                    layoutParams.weight = 0.0f;
                } else {
                    layoutParams.width = 0;
                    layoutParams.weight = 1.0f;
                }
                if (i2 % this.ॱॱ == 0) {
                    layoutParams.setMarginStart(0);
                } else {
                    layoutParams.setMarginStart(ʽ());
                }
                baseDistCard.ˉ().setLayoutParams(layoutParams);
                i2++;
            } else {
                return;
            }
        }
    }

    protected BaseDistCard ॱ(ViewGroup viewGroup) {
        BaseDistCard ˎ = ˎ();
        View ˊ = ˊ();
        viewGroup.addView(ˊ);
        ˎ.ˏ(ˊ);
        ˎ.ॱ(this.ˊ);
        this.ˏॱ.add(ˎ);
        return ˎ;
    }

    private LinearLayout ʻ() {
        LinearLayout linearLayout = new LinearLayout(this.ʼॱ);
        linearLayout.setOrientation(0);
        linearLayout.setLayoutParams(new LayoutParams(-1, -2));
        return linearLayout;
    }

    public List<BaseDistCard> ˋ() {
        return this.ˏॱ;
    }

    protected BaseDistCard ˎ() {
        return new BaseDistCard(this.ʼॱ);
    }

    protected View ˊ() {
        return new View(this.ʼॱ);
    }

    private int ॱॱ() {
        return eib.ˊᐝ();
    }

    private void ˏ(@NonNull BaseMultipleLineVerticalCardBean baseMultipleLineVerticalCardBean) {
        if (this.ʿ != null) {
            this.ʿ.setText(baseMultipleLineVerticalCardBean.v_());
        }
        if (this.ˎ == null) {
            return;
        }
        if (ˋ(baseMultipleLineVerticalCardBean)) {
            this.ˎ.setVisibility(0);
        } else {
            this.ˎ.setVisibility(8);
        }
    }

    private boolean ᐝ() {
        if (this.ʽ == 0 || this.ʽ == this.ॱॱ) {
            return false;
        }
        return true;
    }

    public void ॱ(final chy o_chy) {
        this.ˊ = o_chy;
        if (this.ˎ != null) {
            this.ˎ.setOnClickListener(new evx(this) {
                final /* synthetic */ BaseMultipleLineVerticalCard ˏ;

                public void ˋ(View view) {
                    if (o_chy != null) {
                        o_chy.ˏ(9, this.ˏ);
                    }
                }
            });
        }
    }

    protected void ˎ(int i, List<BaseDistCardBean> list) {
        for (int i2 = 0; i2 < i; i2++) {
            BaseDistCardBean baseDistCardBean = (BaseDistCardBean) list.get(i2);
            if (i2 > (i - this.ॱॱ) - 1) {
                baseDistCardBean.ʻ(true);
            } else {
                baseDistCardBean.ʻ(false);
            }
        }
    }

    protected boolean ˋ(BaseMultipleLineVerticalCardBean baseMultipleLineVerticalCardBean) {
        return (dof.ॱ(baseMultipleLineVerticalCardBean.ॱॱ()) || CollectCheck.isEmpty(baseMultipleLineVerticalCardBean.ˊ()) || baseMultipleLineVerticalCardBean.ˊ().size() < this.ˏ) ? false : true;
    }

    protected boolean ॱ(BaseMultipleLineVerticalCardBean baseMultipleLineVerticalCardBean) {
        return !CollectCheck.isEmpty(baseMultipleLineVerticalCardBean.ˊ());
    }

    protected void ॱ(View view) {
    }

    protected int ʽ() {
        return (int) this.ʼॱ.getResources().getDimension(d.ˉ);
    }

    protected void ˋ(LinearLayout linearLayout) {
        linearLayout.setPaddingRelative(linearLayout.getPaddingStart(), (int) this.ʼॱ.getResources().getDimension(d.ͺˎ), linearLayout.getPaddingEnd(), linearLayout.getPaddingBottom());
    }
}
